package com.bolt.support.ui.tree.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ZTree 节点数据结构
 * Created by michao on 2017/10/30.
 */
@Data
@JsonSerialize(using = UITreeNodeSerialize.class)
public class UITreeNode implements Serializable {

    private String id;

    private String icon;

    private String name;

    private String url;

    private String title;

    private String pId;

    @JsonProperty("isOpen")
    private boolean open;

    private boolean nocheck;

    @JsonProperty("isParent")
    private boolean parent;

    @JsonProperty("isHidden")
    private boolean hidden;

    private boolean leaf;

    private boolean checked;

    @JsonIgnore
    private Map attribute = new HashMap();


    private List<UITreeNode> children;


    public Map putAttribute(String key, String value) {
        this.attribute.put(key, value);
        return this.attribute;
    }

    public void putAllAttribute(Map attribute) {
        this.attribute.putAll(attribute);
    }

    /**
     * 是否有子项
     *
     * @return
     */
    public boolean hasChildren() {
        return parent || (getChildren() != null && !getChildren().isEmpty());
    }


}
